﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;
using exsportance.Silverlight.Common.Utils;

namespace exsportance.Silverlight.Validate.Validators
{
    /// <summary>
    /// Validator for fields where a value is required
    /// </summary>
    public class NotEmptyValidator : BaseValidator
    {
        #region members
        /// <summary>
        /// Validation failure message key for when the value is an empty string
        /// </summary>
        private const string IS_EMPTY = "isEmpty";

        protected Dictionary<string, string> _messagesTemplates = new Dictionary<string, string>(){
        {NotEmptyValidator.IS_EMPTY,"Value is required and can't be empty"},
        };
        #endregion

        #region protected methods
        protected override bool CheckValid(object value)
        {

            if (value == null)
            {
                raiseMessage(NotEmptyValidator.IS_EMPTY);
                return false;
            }
            else
            {
                if (value is string)
                {
                    if (String.IsNullOrEmpty(value as string))
                    {
                        raiseMessage(NotEmptyValidator.IS_EMPTY);
                        return false;
                    }

                }
                else
                {
                    if (value.ToString().IsNullOrEmpty())
                    {
                        raiseMessage(NotEmptyValidator.IS_EMPTY);
                        return false;
                    }
                }
            }

            return true;
        }

        protected override System.Collections.Generic.Dictionary<string, string> getMessageTemplates()
        {
            return _messagesTemplates;
        }
        #endregion
    }
}
